package hypeerweb.connected;

import hypeerweb.SimplifiedNodeDomain;
import hypeerweb.node.Contents;
import hypeerweb.node.Node;
import hypeerweb.node.NodeInterface;
import hypeerweb.node.NodeState;
import hypeerweb.node.WebId;
import hypeerweb.visitor.Parameters;
import hypeerweb.visitor.Visitor;

/**
 * Wrapper that goes into the connections class for what
 * is used to handle modifying connections
 * @author Levi Schuck
 *
 */
public abstract class ConnectedNode implements NodeInterface, Comparable<ConnectedNode>{
	
	protected Node myNode;
	
	public abstract void addMe(Node n);
	public abstract void removeMe(Node n);
	
	public void replace(Node n, Node n2) {
		// TODO Auto-generated method stub
		removeMe(n);
		addMe(n2);
	}
	
	// Now for the main wrapper

	@Override
	public SimplifiedNodeDomain constructSimplifiedNodeDomain() {
		return myNode.constructSimplifiedNodeDomain();
	}

	@Override
	public void addToHyPeerWeb(Node newNode) {
		myNode.addToHyPeerWeb(newNode);
	}
	
	@Override
	public void addNeighbor(Node neighbor) {
		myNode.addNeighbor(neighbor);
	}

	@Override
	public void removeNeighbor(Node neighbor) {
		myNode.removeNeighbor(neighbor);
	}

	@Override
	public void addUpPointer(Node upPointer) {
		myNode.addUpPointer(upPointer);
	}

	@Override
	public void removeUpPointer(Node upPointer) {
		myNode.removeUpPointer(upPointer);
	}

	@Override
	public void addDownPointer(Node downPointer) {
		myNode.addDownPointer(downPointer);
	}

	@Override
	public void removeDownPointer(Node downPointer) {
		myNode.removeDownPointer(downPointer);
	}

	@Override
	public void setFold(Node newFold) {
		myNode.setFold(newFold);
	}

	@Override
	public void setSurrogateFold(Node newSurrogateFold) {
		myNode.setSurrogateFold(newSurrogateFold);
	}

	@Override
	public void setInverseSurrogateFold(Node newInverseSurrogateFold) {
		myNode.setInverseSurrogateFold(newInverseSurrogateFold);
	}

	@Override
	public WebId getWebId() {
		return myNode.getWebId();
	}

	@Override
	public void setWebId(WebId id) {
		myNode.setWebId(id);
	}
	@Override
	public String toString() {
		return myNode.toString();
	}

	@Override
	public void removeFromHyPeerWeb() {
		myNode.removeFromHyPeerWeb();
	}
	@Override
	public void setState(NodeState state) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public NodeState getState() {
		// TODO Auto-generated method stub
		return myNode.getState();
	}
	@Override
	public Node asNode() {
		return myNode;
	}	
	
	@Override
	public int compareTo(ConnectedNode o) {
		return myNode.compareTo(o.asNode());
	}
	
	@Override
	public int hashCode() {
		return getWebId().getValue();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (obj instanceof ConnectedNode) {
			ConnectedNode other = (ConnectedNode) obj;
			if (myNode == null) {
				if (other.myNode != null)
					return false;
			} else if (myNode.getWebId().getValue() != other.myNode.getWebId().getValue())
				return false;
		}
		if (obj instanceof Node) {
			Node other = (Node) obj;
			if (myNode == null) {
				if (other != null)
					return false;
			} else if (myNode.getWebId().getValue() != other.getWebId().getValue())
				return false;
		}
		
		return true;
	}
	
	public Contents getContents() {
		return myNode.getContents();
	}
	
	public void accept(Visitor visitor, Parameters parameters) {
		myNode.accept(visitor, parameters);
	}
}
